package com.zxf.android.mobilesafe.engine;

import java.io.InputStream;

import org.xmlpull.v1.XmlPullParser;

import android.util.Xml;

import com.zxf.android.mobilesafe.bean.UpdateInof;

public class UpdateInfoParser {
	private static UpdateInof info = new UpdateInof();

	public static UpdateInof getUpdateInfo(InputStream is) throws Exception {
		XmlPullParser parser = Xml.newPullParser();
		parser.setInput(is,"utf-8");
		int eventType = parser.getEventType();
		while(eventType != XmlPullParser.END_DOCUMENT) {
			
			switch (eventType) {
			
			case XmlPullParser.START_TAG:
				if("version".equalsIgnoreCase(parser.getName())) {
					info.setVersion(parser.nextText());
				}
				else if("description".equalsIgnoreCase(parser.getName())) {
					info.setDescription(parser.nextText());
				}
				else if("url".equalsIgnoreCase(parser.getName())) {
					info.setUrl(parser.nextText());
				}
				break;
			}
			
			eventType = parser.next();
		}
		return info;
	}

}
